<template>
  <div class="app-container">

    <div class="filter-container">
      <div class="filter-item">
        <span>学校名称：</span>
        <el-select v-model="selectSchoolId" filterable placeholder="请选择" @change="getTemplateContent">
          <el-option
            v-for="item in mapSchool"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </div>
    </div>

    <el-form ref="form" :model="form" label-width="120px">

      <!-----------------------------------------Banner----------------------------------------------->
      <!--<el-divider><span style="color: #20a0ff;font-size: xx-large">Banner</span></el-divider>
      <div style="margin-top: 10px" v-for="(item,index) in form.banners">

        <el-form-item label="院校图片" >
          <el-upload
            class="upload-demo"
            :action="host+'/guard/upload?module=school&type=banner&count='+index"
            accept=".png,.jpg,.jpeg"
            :show-file-list="false"
            :on-success="handleAvatarSuccess">
            <el-button size="small" type="primary">点击上传</el-button>
            <img @click.stop="()=>{}" v-if="item.url" :src="item.url" style="width: 150px;height: 100px;margin-bottom: -12px;margin-left: 32px">
            <el-button v-if="index!=0" style="margin-left: 20px" @click.stop="delBanner(index)" size="small" type="danger">删除此项</el-button>
          </el-upload>



        </el-form-item>

        <el-form-item label="标题">
          <el-input v-model="item.title" placeholder="标题"></el-input>
        </el-form-item>

        <el-form-item label="副标题">
          <el-input v-model="item.sub_title" placeholder="副标题"></el-input>
        </el-form-item>

      </div>
      <el-button   @click="add('banner')" style="margin-left: 78px" type="primary">添加</el-button>-->

      <!--官方招生政策声明-->
      <el-divider ><span style="color: #20a0ff;font-size: xx-large">官方招生政策声明</span></el-divider>
      <div v-for="(item,index) in form.official_policy">

        <el-row>
          <el-col :span="6">
            <el-form-item label="证书：" >
              <el-upload
                class="avatar-uploader"
                :action="host+'/guard/upload?module=school&type=official_policy&count='+index"
                accept=".png,.jpg,.jpeg"
                :show-file-list="false"
                :before-upload="beforeAvatarUpload"
                :on-success="handleAvatarSuccess">
                <img style="width: 100px;height: 100px" v-if="item.url" :src="item.url" class="avatar">
                <i  v-else class="el-icon-plus avatar-uploader-icon"></i>
              </el-upload>
            </el-form-item>
          </el-col>
          <el-col :span="18">
            <el-button @click="delCert()" type="danger" size="small">删除证书</el-button>
          </el-col>
        </el-row>

        <el-form-item>
          <span style="color: red">*图片格式限制为JPG\JPEG,最大不能超过5M,建议图片大小:685x386</span>
        </el-form-item>



        <el-form-item label="声明标题：">
          <el-input v-model="item.title" placeholder="请输入"></el-input>
        </el-form-item>
        <el-form-item label="内容：">
          <el-input rows="5" type="textarea" v-model="item.content" placeholder="内容"></el-input>
        </el-form-item>

        <el-form-item>
          <span style="color: red">需要空格时请输入“/tab”，一个“/tab”代表一个空格，输入多个请连续输入/tab/tab</span>
        </el-form-item>

      </div>


      <!-------------------------------------------学校简介---------------------------------------------->
      <el-divider ><span style="color: #20a0ff;font-size: xx-large">学校简介</span></el-divider>
      <div v-for="(item,index) in form.summary">
        <el-form-item label="图片：" >
          <el-upload
            class="avatar-uploader"
            :action="host+'/guard/upload?module=school&type=summary&count='+index"
            accept=".png,.jpg,.jpeg"
            :show-file-list="false"
            :before-upload="beforeAvatarUpload"
            :on-success="handleAvatarSuccess">
            <img style="width: 100px;height: 100px" v-if="item.url" :src="item.url" class="avatar">
            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>
          <span style="color: red">*图片格式限制为JPG\JPEG,最大不能超过5M,建议图片大小:273×380</span>
        </el-form-item>

        <el-form-item label="内容：">
          <el-input rows="5" type="textarea" v-model="item.content" placeholder="内容"></el-input>
        </el-form-item>

        <el-form-item v-for="(textItem,textIndex) in item.desc" label="院校排名：">
          <el-row  :gutter="10">
            <el-col :span="6">
              <el-input v-model="textItem.text1" placeholder="请输入名字"></el-input>
              <span style="color: red" v-if="textIndex==item.desc.length-1">请输入1-4字排名</span>
            </el-col>
            <el-col :span="6">
              <el-input v-model="textItem.text2" placeholder="请输入排行榜"></el-input>
              <span style="color: red" v-if="textIndex==item.desc.length-1">请输入1-8字排行榜</span>
            </el-col>
            <el-col :span="6">
              <el-input v-model="textItem.text3" placeholder="请输入英文翻译"></el-input>
              <span style="color: red" v-if="textIndex==item.desc.length-1">请输入1-8字英文翻译</span>
            </el-col>
            <el-col :span="2"><el-button size="small" type="primary" @click="add('summary')">添加</el-button></el-col>
            <el-col :span="2"><el-button v-if="textIndex!=0" size="small" type="danger" @click="delSummary(textIndex)">删除</el-button></el-col>
          </el-row>
        </el-form-item>

        <!--<el-form-item>
          <el-col :span="6"><span>请输入1-4字排名</span></el-col>
          <el-col :span="6"><span>请输入1-8字排行榜</span></el-col>
          <el-col :span="6"><span>请输入1-8字英文翻译</span></el-col>
          <el-col :span="2"><el-button size="small" type="primary">添加</el-button></el-col>
          <el-col :span="2"><el-button size="small" type="danger" >删除</el-button></el-col>
        </el-form-item>-->

        <el-form-item label="分校图片：" >
          <el-upload
            class="avatar-uploader"
            :action="host+'/guard/upload?module=school&type=dutSummary&count='+index"
            accept=".png,.jpg,.jpeg"
            :show-file-list="false"
            :before-upload="beforeAvatarUpload"
            :on-success="handleAvatarSuccess">
            <img style="width: 100px;height: 100px" v-if="item.dutUrl" :src="item.dutUrl" class="avatar">
            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>
          <span style="color: red">*图片格式限制为JPG\JPEG,最大不能超过5M,建议图片大小:273×380</span>
        </el-form-item>
        <el-form-item label="分校内容：">
          <el-input rows="5" type="textarea" v-model="item.dutContent" placeholder="内容"></el-input>
        </el-form-item>

      </div>

      <!------------------------------------------01报名条件---------------------------------------------->
      <el-divider ><span style="color: #20a0ff;font-size: xx-large">01报名条件</span></el-divider>
      <div v-for="(item,index) in form.apply_conditions">

        <el-row v-for="(text,index) in item.middle">

          <el-col :span="6">
            <el-form-item :label="'报名条件'+(index+1)+'：'"><el-input placeholder="请输入" v-model="text.label_title"></el-input></el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item :label="'英文名：'"><el-input placeholder="请输入" v-model="text.english_title"></el-input></el-form-item>
          </el-col>

          <el-col :span="6">
            <el-form-item  :label="'招生要求：'"><el-input placeholder="请输入" v-model="text.title"></el-input></el-form-item>
            <!--<el-form-item  v-if="index==0" label="本科成绩："><el-input placeholder="请输入" v-model="text.title"></el-input></el-form-item>
            <el-form-item  v-if="index==1" label="免考语言："><el-input placeholder="请输入" v-model="text.title"></el-input></el-form-item>
            <el-form-item  v-if="index==2" label="学历/学位证："><el-input placeholder="请输入" v-model="text.title"></el-input></el-form-item>-->
          </el-col>
          <el-col :span="6">
            <el-form-item label="注意事项："><el-input placeholder="请输入" v-model="text.sub_title"></el-input></el-form-item>
          </el-col>
        </el-row>


        <el-form-item label="图片：" >
          <el-upload
            class="avatar-uploader"
            :action="host+'/guard/upload?module=school&type=applyCondition&count='+index"
            accept=".png,.jpg,.jpeg"
            :show-file-list="false"
            :before-upload="beforeAvatarUpload"
            :on-success="handleAvatarSuccess">
            <img style="width: 100px;height: 100px" v-if="item.back_pic.url" :src="item.back_pic.url" class="avatar">
            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>
          <span style="color: red">*图片格式限制为JPG\JPEG,最大不能超过5M,建议图片大小:673x418</span>
        </el-form-item>


        <el-form-item  label="奖学金要求01：">
          <el-input v-model="item.right[0].text1" placeholder="请输入"></el-input>
        </el-form-item>
        <el-form-item  label="奖学金要求02：">
          <el-input v-model="item.right[0].text2" placeholder="请输入"></el-input>
        </el-form-item>
        <el-form-item  label="奖学金要求03：">
          <el-input v-model="item.right[0].text3" placeholder="请输入"></el-input>
        </el-form-item>
      </div>


      <!--------------------------------------------02研究生申请流程-------------------------------------------->
      <el-divider ><span style="color: #20a0ff;font-size: xx-large">02研究生申请流程</span></el-divider>
      <div v-for="(item,index) in form.graduate_student">
        <el-form-item  label="申请流程：">
          <el-row  :gutter="10">
            <el-col style="margin-top: 10px" v-for="(item,index) in item.icons" :span="6">
              <img style="width: 50px;height: 50px" :src="item.url">
              <el-checkbox  v-model="item.is_show"></el-checkbox>
              <el-input v-model="item.name"></el-input>
            </el-col>
          </el-row>
        </el-form-item>

        <el-form-item label="报名方式：" >
          <el-upload
            class="avatar-uploader"
            :action="host+'/guard/upload?module=school&type=graduate&count='+index"
            accept=".png,.jpg,.jpeg"
            :show-file-list="false"
            :before-upload="beforeAvatarUpload"
            :on-success="handleAvatarSuccess">
            <img style="width: 100px;height: 100px" v-if="item.apply.url" :src="item.apply.url" class="avatar">
            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>
          <span style="color: red">*图片格式限制为JPG\JPEG,最大不能超过5M,建议图片大小:78.94x79.56</span>
        </el-form-item>

        <el-form-item label="资格审核：">
          <el-input rows="3" type="textarea" v-model="item.qual_check" placeholder="资格审查"></el-input>
        </el-form-item>

        <el-form-item label="现场复试-正文：">
          <el-input v-model="item.scene_review.content" ></el-input>
        </el-form-item>
        <el-form-item label="现场复试-条件：">
          <el-input v-model="item.scene_review.conditions" placeholder="用中文逗号分割" ></el-input>
        </el-form-item>

      </div>

      <!--------------------------------------------------03专业招生------------------------------------------------------->
      <el-divider ><span style="color: #20a0ff;font-size: xx-large">03专业招生</span></el-divider>
      <div style="margin-top: 10px" v-for="(item,index) in form.student_major[0].major_names">

        <el-row>
          <el-col :span="12">
            <el-form-item label="图片：" >
              <el-upload
                class="avatar-uploader"
                :action="host+'/guard/upload?module=school&type=major&count='+index"
                accept=".png,.jpg,.jpeg"
                :show-file-list="false"
                :before-upload="beforeAvatarUpload"
                :on-success="handleAvatarSuccess">
                <img style="width: 100px;height: 100px" v-if="item.url" :src="item.url" class="avatar">
                <i v-else class="el-icon-plus avatar-uploader-icon"></i>
              </el-upload>
              <span style="color: red">*图片格式限制为JPG\JPEG,最大不能超过5M,建议图片大小:321x399</span>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item >
              <el-button  v-if="index!=0" size="small" type="danger" @click="delMajor(index)" >删除</el-button>
            </el-form-item>
          </el-col>
        </el-row>

        <el-form-item label="学校/专业名称：">
          <el-input v-model="item.title" placeholder="请输入"></el-input>
        </el-form-item>

        <el-form-item label="英文名称：">
          <el-input v-model="item.sub_title" placeholder="请输入"></el-input>
        </el-form-item>
        <el-form-item label="学分：">
          <el-input v-model="item.point" placeholder="请输入"></el-input>
        </el-form-item>
        <el-form-item label="简介：">
          <el-input type="textarea" rows="3" v-model="item.summary" placeholder="请输入"></el-input>
        </el-form-item>
        <el-form-item label="专业/课程名称：">
          <el-input v-model="item.class_names_title" placeholder="请输入"></el-input>
        </el-form-item>
        <el-form-item label="详细内容：">
          <el-input v-model="item.class_names" placeholder="请用中文逗号隔开"></el-input>
        </el-form-item>

      </div>
      <el-button   @click="add('major')" style="margin-left: 78px" type="primary">添加</el-button>


      <!--04院校新闻-->
      <!--<el-divider ><span style="color: #20a0ff;font-size: xx-large">04院校新闻</span></el-divider>
      <div style="margin-top: 10px" v-for="(item,index) in form.school_news">

        <el-form-item label="资讯图片" >
          <el-upload
            class="upload-demo"
            :action="host+'/guard/upload?module=school&type=news&count='+index"
            accept=".png,.jpg,.jpeg"
            :show-file-list="false"
            :on-success="handleAvatarSuccess">
            <el-button size="small" type="primary">点击上传</el-button>
            &lt;!&ndash;<el-button size="small" type="danger">删除此项</el-button>&ndash;&gt;
            <img v-if="item.url" :src="item.url" style="width: 150px;height: 100px;margin-bottom: -12px;margin-left: 32px">
          </el-upload>
        </el-form-item>

        <el-form-item label="标题">
          <el-input v-model="item.title" placeholder="标题"></el-input>
        </el-form-item>
        <el-form-item label="简介">
          <el-input type="textarea" rows="3" v-model="item.summary" placeholder="简介"></el-input>
        </el-form-item>
      </div>-->

      <!----------------------------------------------------------05校园生活---------------------------------------------->
      <el-divider ><span style="color: #20a0ff;font-size: xx-large">05校园生活</span></el-divider>
      <el-form-item label="图片/视频">
        <el-upload
          :action="host+'/guard/upload?module=school&type=life'"
          list-type="picture-card"
          accept=".jpg,.jpeg,.png,.bmp,.webp,.mp4"
          :file-list="form.school_life[0].pic"
          :on-success="handleUploadSuccess"
          :on-preview="handlePictureCardPreview"
          :on-remove="handleRemove">
          <i class="el-icon-plus"></i>
        </el-upload>
        <span style="color: red">*图片格式限制为JPG\JPEG,最大不能超过5M,建议图片大小:853x480</span>
        <el-dialog :visible.sync="dialogVisible">
          <img width="100%" :src="dialogImageUrl" alt="">
        </el-dialog>
      </el-form-item>

      <el-form-item label="视频封面">
        <el-upload
          :action="host+'/guard/upload?module=school&type=life'"
          list-type="picture-card"
          :file-list="form.school_life[0].cover"
          :on-success="handleUploadCoverSuccess"
          :on-preview="handlePictureCardPreview"
          :on-remove="handleRemove2">
          <i class="el-icon-plus"></i>
        </el-upload>
        <span style="color: red">*图片格式限制为JPG\JPEG,最大不能超过5M,建议图片大小:853x480</span>
        <el-dialog :visible.sync="dialogVisible">
          <img width="100%" :src="dialogImageUrl" alt="">
        </el-dialog>
      </el-form-item>


      <!------------------------------------------------------06研究生录取通知书----------------------------------------------->
      <el-divider ><span style="color: #20a0ff;font-size: xx-large">06{{form.pass[0].big_title}}</span></el-divider>


      <el-form-item label="大标题">
        <el-input v-model="form.pass[0].big_title"></el-input>
      </el-form-item>
      <el-form-item label="英文标题">
        <el-input v-model="form.pass[0].english_title"></el-input>
      </el-form-item>
      <el-form-item label="副标题">
        <el-input v-model="form.pass[0].sub_title"></el-input>
      </el-form-item>


     <el-form-item label="证书：">
       <el-upload
         :action="host+'/guard/upload?module=school&type=pass'"
         list-type="picture-card"
         :file-list="form.pass[0].pic"
         :on-success="handleUploadSuccess"
         :on-preview="handlePictureCardPreview"
         :on-remove="handleRemove1">
         <i class="el-icon-plus"></i>
       </el-upload>
       <span style="color: red">*图片格式限制为JPG\JPEG,最大不能超过5M,建议图片大小:273x380</span>
       <el-dialog :visible.sync="dialogVisible1">
         <img width="100%" :src="dialogImageUrl1" alt="">
       </el-dialog>
     </el-form-item>

      <el-form-item label="标题">
        <el-input v-model="form.pass[0].content[0].title" placeholder="标题"></el-input>
      </el-form-item>
      <el-form-item label="简介">
        <el-input type="textarea" rows="3" v-model="form.pass[0].content[0].summary" placeholder="简介"></el-input>
      </el-form-item>

      <el-form-item label="标题">
        <el-input v-model="form.pass[0].content[1].title" placeholder="标题"></el-input>
      </el-form-item>
      <el-form-item label="简介">
        <el-input type="textarea" rows="3" v-model="form.pass[0].content[1].summary" placeholder="简介"></el-input>
      </el-form-item>



      <!--提交-->
      <el-divider></el-divider>
      <el-form-item label="">
          <el-button  type="primary" @click="onSubmit('form',1)">立即创建</el-button>
         <el-button @click="onSubmit('form',2)">保存草稿</el-button>
      </el-form-item>
    </el-form>





  </div>
</template>

<script>

import { myGet, myPost } from '@/utils/myRequest'

const urlSchool = "/guard/school/lst"
const urlTemplateContent = "/guard/school/getTemplateContent"

export default {
  name: 'templateContent',

  data(){
    return{
      host:process.env.VUE_APP_HOST,
      selectSchoolId:"",
      mapSchool:[],
      url:"",
      imageUrl:"",
      dialogImageUrl: '',
      dialogVisible: false,
      dialogImageUrl1: '',
      dialogVisible1: false,
      form:{
        banners:[
          {
            url:"",
            path:"",
            title:"",
            sub_title:""
          }
        ],
        official_policy:[
          {
            url:"",
            path:"",
            title:"",
            content:""
          }
        ],
        summary:[
          {
            url:"",
            path:"",
            content:"",
            desc:[
              {text1:"",text2:"",text3:""}
            ],
            dutUrl:"",
            dutPath:"",
            dutContent:"",
          }
        ],
        apply_conditions: [
          {
            back_pic:{
              url:"",
              path:""
            },
            middle:[
              {
                label_title:"",
                english_title:"",
                title:"",
                sub_title:"",
              },
              {
                label_title:"",
                english_title:"",
                title:"",
                sub_title:"",
              },
              {
                label_title:"",
                english_title:"",
                title:"",
                sub_title:"",
              }
            ],
            right:[{text1:"",text2:"",text3:""}],
          }
        ],
        graduate_student:[
          {
            icons:[],//从后端获取
            qual_check:"",//资格审核
            scene_review:{
              content:"",
              conditions:"",
            },
            apply:{
              url:"",
              path:""
            }
          }
        ],
        student_major:[
          {
            major_names:[
              {
                url:"",
                path:"",
                title:"",
                sub_title:"",
                point:"",
                summary:"",
                class_names_title:"",
                class_names:""
              }
            ]
          }
        ],
        school_news:[
          {
            url:"",
            path:"",
            title:"",
            summary:""
          },
          {
            url:"",
            path:"",
            title:"",
            summary:""
          }
        ],
        school_life:[
          {
            pic:[],
            cover:[],
          }
        ],
        pass:[
          {
            big_title:"研究生录取通知书",
            english_title:"",
            sub_title:"",
            pic:[],
            content:[{
              title:"",
              summary:"",
            },{
              title:"",
              summary:"",
            }]
          }
        ]
      }
    }
  },

  methods:{

    handleUploadSuccess(res ,file, fileList){
      console.log(res,file,fileList)
      const type = res.data.records.type
      if(type=='pass'){
        this.form.pass[0].pic.push({
          url:res.data.records.url,
          path:res.data.records.filePath,
          uid:file.uid
        })
      }else{
        this.form.school_life[0].pic.push({
          url:res.data.records.url,
          path:res.data.records.filePath,
          uid:file.uid
        })
      }
    },

    //单独用于 校园生活 上传视频封面的 回调
    handleUploadCoverSuccess(res ,file, fileList){
      console.log(res,file,fileList)
      const type = res.data.records.type
      this.form.school_life[0].cover.push({
        url:res.data.records.url,
        path:res.data.records.filePath,
        uid:file.uid
      })
    },
    handleRemove(file, fileList) {
      for (let i = 0; i < this.form.school_life[0].pic.length ; i++) {
        if(file.uid==this.form.school_life[0].pic[i].uid){
          this.form.school_life[0].pic.splice(i,1)
        }
      }
      //console.log(this.form.school_life[0].pic)
    },
    handleRemove2(file, fileList) {
      for (let i = 0; i < this.form.school_life[0].cover.length ; i++) {
        if(file.uid==this.form.school_life[0].cover[i].uid){
          this.form.school_life[0].cover.splice(i,1)
        }
      }
      //console.log(this.form.school_life[0].pic)
    },
    handleRemove1(file, fileList) {
      for (let i = 0; i < this.form.pass[0].pic.length ; i++) {
        if(file.uid==this.form.pass[0].pic[i].uid){
          this.form.pass[0].pic.splice(i,1)
        }
      }
      //console.log(this.form.pass[0].pic)
    },
    handlePictureCardPreview(file) {
      this.dialogImageUrl = file.url;
      this.dialogVisible = true;
    },
    onSubmit(formName,is_finished_template) {
      this.$refs[formName].validate((valid)=>{
        if(valid){

          console.log(this.form)
          const url = urlTemplateContent
          myPost(url,{id:this.selectSchoolId,template_content:this.form,is_finished_template:is_finished_template}).then(res => {
            if (res.status) {
              this.$message.success(res.msg)
              this.$router.push('/lstSchool')
            }
          })
        }
      })
    },
    add(type){
      if(type=='banner'){
        this.form.banners.push({
          url:"",
          path:"",
          title:"",
          sub_title:""
        })
      }else if(type=='summary'){
        this.form.summary[0].desc.push({text1:"",text2:"",text3:""})
      }else if(type=='major'){
        this.form.student_major[0].major_names.push(
          {
            url:"",
            path:"",
            title:"",
            sub_title:"",
            point:"",
            summary:"",
            class_names_title:"",
            class_names:""
          }
        )
      }else{

      }
    },

    delCert(index){
      this.form.official_policy[0].url = "";
      this.form.official_policy[0].path = "";
    },
    delMajor(index){
      this.form.student_major[0].major_names.splice(index,1)
    },

    delBanner(index){
      this.form.banners.splice(index,1)
    },

    delSummary(index){
      this.form.summary[0].desc.splice(index,1)
    },

    beforeAvatarUpload(file) {
      const isLt2M = file.size / 1024 / 1024 < 5;
      if (!isLt2M) {
        this.$message.error('上传头像图片大小不能超过 5MB!');
      }
      return isLt2M;
    },

    handleAvatarSuccess(res, file) {
      if(res.status){
        const type = res.data.records.type
        const index = res.data.records.count
        console.log(res.data.records)

        if(type=='banner'){
          this.form.banners[index].url = res.data.records.url
          this.form.banners[index].path = res.data.records.filePath
        }else if(type=='official_policy'){
          this.form.official_policy[0].url = res.data.records.url
          this.form.official_policy[0].path = res.data.records.filePath
        }else if(type=='major'){
          this.form.student_major[0].major_names[index].url = res.data.records.url
          this.form.student_major[0].major_names[index].path = res.data.records.filePath

          console.log(this.form.student_major)
        } else if(type=='news'){
          this.form.school_news[index].url = res.data.records.url
          this.form.school_news[index].path = res.data.records.filePath

        } else if(type=='summary'){

          this.form.summary[0].url = res.data.records.url
          this.form.summary[0].path = res.data.records.filePath

        } else if(type=='dutSummary'){

          this.form.summary[0].dutUrl = res.data.records.url
          this.form.summary[0].dutPath = res.data.records.filePath

        }else if(type=='applyCondition'){
            console.log(this.form.apply_conditions)
          this.form.apply_conditions[0].back_pic.url = res.data.records.url
          this.form.apply_conditions[0].back_pic.path = res.data.records.path

        } else if(type=='graduate'){
          console.log('graduate',this.form.graduate_student[0].apply.url)

          this.form.graduate_student[0].apply.url = res.data.records.url
          this.form.graduate_student[0].apply.path = res.data.records.filePath

        } else{

        }
      }else{
        this.$message.error('上传失败!')
      }
    },

    async getSchool(){
      await myGet(urlSchool).then(res=>{
        if(res.status){
          this.mapSchool = []
          res.data.records.forEach(item=>{
            this.mapSchool.push({
              value:item.id,
              label:item.name
            })
          })
          this.selectSchoolId = this.mapSchool[0].value
        }
      })
    },

    getTemplateContent(){
      const url = urlTemplateContent+"?id="+this.selectSchoolId
      myGet(url).then(res=>{
        if(res.status){

          //添加文章
          const article = res.data.records.article
          if(article.length>0){
            for (let i = 0; i < article.length; i++) {
              this.form.school_news[i].url = article[i].url
              this.form.school_news[i].cover_url = article[i].cover_url
              this.form.school_news[i].title = article[i].title
              this.form.school_news[i].summary = article[i].description
            }
          }
          const school = JSON.parse(res.data.records.school.template_content)
          console.log(school)

          if(school == undefined || school == null || school == ''|| school.length==0 ){
            Object.assign(this.form ,this.$options.data().form)
            this.form.graduate_student[0].icons = res.data.records.icons
          }else{
            Object.assign(this.form,school)
            if(this.form.graduate_student[0].icons.length<=0){
              this.form.graduate_student[0].icons = res.data.records.icons
            }
          }



        }//end if
      })
    },
  },

  mounted() {
    this.getSchool().then(()=>{
      this.getTemplateContent()
    })

  }
}
</script>

<style>

.el-divider--horizontal{
  margin-top: 48px;
  margin-bottom: 48px;
}

.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409EFF;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 150px;
  height: 150px;
  line-height: 150px;
  text-align: center;
}
.avatar {
  width: 178px;
  height: 178px;
  display: block;
}


</style>
